package com.example.tiaociweb.Controller;
import com.example.tiaociweb.Service.CeramicService;
import com.example.tiaociweb.entity.Ceramic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import java.util.Collections;
import java.util.List;

@Controller
public class HomeController {

    @Autowired
    private CeramicService ceramicService;

    @GetMapping("/")
    public String index(Model model) {
        try {
            List<Ceramic> ceramics = ceramicService.findAll();
            model.addAttribute("ceramics", ceramics != null ? ceramics : Collections.emptyList());
        } catch (Exception e) {
            // 记录日志并返回空列表或错误页面
            model.addAttribute("ceramics", Collections.emptyList());
        }
        return "index";
    }

}